import { ref } from 'vue'
import { defineStore } from 'pinia'
// import { UserType } from '@/modules/user'

export const useUserStore = defineStore('user', () => {
  const savedUser = localStorage.getItem('userInfo')
  const userInfo = ref(savedUser ? JSON.parse(savedUser) : {})
  const getCurrentUser = () => {
    return userInfo.value
  }
  const setCurrentUser = (user: any) => {
    userInfo.value = user
     localStorage.setItem('userInfo', JSON.stringify(user)) // 存入 localStorage
    return userInfo.value
  }

  return { getCurrentUser, setCurrentUser }
})
